<link href="${base}/resources/favicon.ico" rel="icon">
<link href="${base}/resources/common/css/bootstrap.css" rel="stylesheet">
<link href="${base}/resources/common/css/iconfont.css" rel="stylesheet">
<link href="${base}/resources/common/css/iconfont1.css" rel="stylesheet">
<link href="${base}/resources/common/css/font-awesome.css" rel="stylesheet">
<link href="${base}/resources/common/css/bootstrap-select.css" rel="stylesheet">
<link href="${base}/resources/common/css/ajax-bootstrap-select.css" rel="stylesheet">
<link href="${base}/resources/common/css/awesome-bootstrap-checkbox.css" rel="stylesheet">
<link href="${base}/resources/common/css/bootstrap-fileinput.css" rel="stylesheet">
<link href="${base}/resources/common/css/summernote.css" rel="stylesheet">
<link href="${base}/resources/common/css/bootstrap-datetimepicker.css" rel="stylesheet">
<link href="${base}/resources/common/css/base.css" rel="stylesheet">
<link href="${base}/resources/admin/css/base.css" rel="stylesheet">
<!--[if lt IE 9]>
    <script src="${base}/resources/common/js/html5shiv.js"></script>
    <script src="${base}/resources/common/js/respond.js"></script>
    <![endif]-->
<script src="${base}/resources/common/js/jquery.js"></script>
<script src="${base}/resources/common/js/bootstrap.js"></script>
<script src="${base}/resources/common/js/bootstrap-growl.js"></script>
<script src="${base}/resources/common/js/bootstrap-select.js"></script>
<script src="${base}/resources/common/js/ajax-bootstrap-select.js"></script>
<script src="${base}/resources/common/js/Sortable.js"></script>
<script src="${base}/resources/common/js/jquery-sortable.js"></script>
<script src="${base}/resources/common/js/bootstrap-fileinput.js"></script>
<script src="${base}/resources/common/js/summernote.js"></script>
<script src="${base}/resources/common/js/moment.js"></script>
<script src="${base}/resources/common/js/bootstrap-datetimepicker.js"></script>
<script src="${base}/resources/common/js/jquery.nicescroll.js"></script>
<script src="${base}/resources/common/js/jquery.validate.js"></script>
<script src="${base}/resources/common/js/jquery.validate.additional.js"></script>
<script src="${base}/resources/common/js/jquery.form.js"></script>
<script src="${base}/resources/common/js/jquery.cookie.js"></script>
<script src="${base}/resources/common/js/lodash.js"></script>
<script src="${base}/resources/common/js/URI.js"></script>
<script src="${base}/resources/common/js/bootbox.js"></script>
<script src="${base}/resources/common/js/velocity.js"></script>
<script src="${base}/resources/common/js/velocity.ui.js"></script>
<script src="${base}/resources/common/js/base.js"></script>
<script src="${base}/resources/admin/js/base.js"></script>

<script>
    $().ready(function () {
        let $resetAll = $(".reset-all");
        let $filterModal = $("#filterModal");

        $resetAll.click(function () {
            $filterModal.find("input").val("");
            $filterModal.find(".selectpicker").val("");
            $filterModal.find(".selectpicker").selectpicker("refresh");
            $filterModal.find(".select").val("");
            $filterModal.find("input:checkbox").removeAttr("checked");
            $filterModal.find("input:radio").removeAttr("checked");

            // 回调函数，需要在包含页面提供该函数
            if (filterCallback && typeof filterCallback === "function") {
                filterCallback();
            }
        });


        [#if !filterDates?? || filterDates?size == 0]
        let $dateContainer = $("#dateContainer");
        $dateContainer.on("click", "div.date-item", function () {
            setBeginEndDate($(this));
        });
        [#else]
        [#list filterDates as filterDate]
        let $dateContainer${filterDate_index} = $("#dateContainer[#if filterDate_index > 0]_${filterDate_index}[/#if]");
        $dateContainer${filterDate_index}.on("click", "div.date-item", function () {
            setBeginEndDate($(this));
        });
        [/#list]

        [/#if]

        function setBeginEndDate(_this) {

            let day = Number(_this.data("day"));
            let $formControl = _this.closest("div.form-group")
            let $beginDate = $formControl.find("input.begin-date");
            let $endDate = $formControl.find("input.end-date");

            if (day === 999999999) {
                $beginDate.val("");
                $endDate.val("");
                return;
            }

            let now = new Date();

            let subtractDate = subtract(day);
            $beginDate.val(beginDate(subtractDate));
            if (day <= 0) {
                $endDate.val(endDate(subtractDate));
            } else {
                $endDate.val(endDate(now));
            }
        }

        function subtract(day) {
            day = day < 0 ? -day : day;
            let now = new Date();
            let dateMillis = now.getTime();
            let dayMillis = day * 24 * 60 * 60 * 1000;
            now.setTime(dateMillis - dayMillis);
            return now;
        }

        function endDate(date) {
            date.setHours(23);
            date.setMinutes(59)
            date.setSeconds(59);
            return format(date, "[#if isIgnoreKeyPrefix?? && isIgnoreKeyPrefix]yyyy-MM-dd HH:mm:ss[#else]yyyy-MM-dd[/#if]");
        }

        function beginDate(date) {
            date.setHours(0);
            date.setMinutes(0)
            date.setSeconds(0);
            return format(date, "[#if isIgnoreKeyPrefix?? && isIgnoreKeyPrefix]yyyy-MM-dd HH:mm:ss[#else]yyyy-MM-dd[/#if]");
        }

        function format(date, fmt) {
            let o = {
                "M+": date.getMonth() + 1,                 //月份
                "d+": date.getDate(),                    //日
                "H+": date.getHours(),                   //小时
                "m+": date.getMinutes(),                 //分
                "s+": date.getSeconds(),                 //秒
                "q+": Math.floor((date.getMonth() + 3) / 3), //季度
                "S": date.getMilliseconds()             //毫秒
            };
            if (/(y+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
            }
            for (let k in o) {
                if (new RegExp("(" + k + ")").test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                }
            }
            return fmt;
        }

    });
</script>

[#include "/admin/template/csrf.ftl" /]